package net.microfigure.service.impl;

import net.microfigure.model.Family;
import net.microfigure.model.FamilyInfo;
import net.microfigure.commons.result.PageInfo;
import net.microfigure.mapper.FamilyInfoMapper;
import net.microfigure.mapper.FamilyMapper;
import net.microfigure.service.IFamilyInfoService;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 林景锋
 * @since 2018-06-15
 */
@Service
public class FamilyInfoServiceImpl extends ServiceImpl<FamilyInfoMapper, FamilyInfo> implements IFamilyInfoService {

	@Autowired
	private FamilyInfoMapper familyInfoMapper;
	@Autowired
	private FamilyMapper familyMapper;
	
	@Override
	public void selectDataGrid(PageInfo pageInfo) {
		Page<FamilyInfo> page = new Page<FamilyInfo>(pageInfo.getNowpage(), pageInfo.getSize());
		EntityWrapper<FamilyInfo> wrapper = new EntityWrapper<FamilyInfo>();
//		String name = "admin";
//		String areaNo = familyInfoMapper.selectListcodeByname(name);
//		System.out.println("输出当前"+areaNo);
//		wrapper.where("area_no = {0}",areaNo);
		wrapper.orderBy(pageInfo.getSort(),pageInfo.getOrder().equalsIgnoreCase("ASC"));
		selectPage(page,wrapper);
		pageInfo.setRows(page.getRecords());
		pageInfo.setTotal(page.getTotal());
		
	}

	@Override
	public String selectIdByFamilyHousemaster(String housemaster) {
		// TODO Auto-generated method stub
		 return familyInfoMapper.selectIdByFamilyHousemaster(housemaster);
	}

	@Override
	public void selectDataGrid(PageInfo pageInfo, String familyNo) {
		Page<FamilyInfo> page = new Page<FamilyInfo>(pageInfo.getNowpage(), pageInfo.getSize());
		EntityWrapper<FamilyInfo> wrapper = new EntityWrapper<FamilyInfo>();
//		String name = "admin";
//		String areaNo = familyInfoMapper.selectListcodeByname(name);
//		System.out.println("dddddddddddddddddddddddddddddddddddd");
//		System.out.println("housemaster=="+housemaster);
////		String family_no =familyInfoMapper.selectIdByFamilyHousemaster(housemaster);
////		System.out.println("输出当前"+family_no);
//		String family_no =familyMapper.selectFamilyNoByHousemaster(housemaster);
//		System.out.println("dddddddddddddddddddddddddddddddddddd");
		
		System.out.println("输出当前"+familyNo);
		wrapper.where("family_no = {0}", familyNo);
//		wrapper.where("area_no = {0}",areaNo);
		wrapper.orderBy(pageInfo.getSort(),pageInfo.getOrder().equalsIgnoreCase("ASC"));
		selectPage(page,wrapper);
		pageInfo.setRows(page.getRecords());
		pageInfo.setTotal(page.getTotal());
		
	}

	@Override
	public List<FamilyInfo> selectListByCardNo(String cardNo) {
		
		return familyInfoMapper.selectListByCardNo(cardNo);
	}

	@Override
	public Integer selectMaxfamilyInfoByfamilyNo(String familyNo) {
		// TODO Auto-generated method stub
		return familyInfoMapper.selectMaxfamilyInfoByfamilyNo(familyNo);
	}

	@Override
	public FamilyInfo selectByFamilyInfoNo(Integer familyInfoNo) {
		// TODO Auto-generated method stub
		return familyInfoMapper.selectByFamilyInfoNo(familyInfoNo);
	}

	@Override
	public void selectDataGrid2(PageInfo pageInfo, String cardNo) {
		Page<FamilyInfo> page = new Page<FamilyInfo>(pageInfo.getNowpage(), pageInfo.getSize());
		EntityWrapper<FamilyInfo> wrapper = new EntityWrapper<FamilyInfo>();
		System.out.println("输出当前"+cardNo);
		wrapper.where("card_no", cardNo);
		wrapper.orderBy(pageInfo.getSort(),pageInfo.getOrder().equalsIgnoreCase("ASC"));
		selectPage(page,wrapper);
		pageInfo.setRows(page.getRecords());
		pageInfo.setTotal(page.getTotal());
		
	}
	
}
